# ACE Agrovet Consults - cPanel Node.js Application .htaccess
# This file configures the web server for Node.js application hosting on cPanel

# Enable rewrite engine
RewriteEngine On

# Redirect HTTP to HTTPS (uncomment if SSL is enabled)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# If the request is for a static file that exists, serve it directly
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# If the request is for a directory that exists, serve it directly
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# For all other requests, proxy to the Node.js application
# Replace PORT with your actual Node.js application port
# The port is typically set in cPanel's "Setup Node.js App" interface
RewriteRule ^(.*)$ http://127.0.0.1:PORT/$1 [P,L]

# Set headers for security
<IfModule mod_headers.c>
    # Prevent clickjacking
    Header always set X-Frame-Options "SAMEORIGIN"
    
    # Prevent MIME type sniffing
    Header always set X-Content-Type-Options "nosniff"
    
    # Enable XSS protection
    Header always set X-XSS-Protection "1; mode=block"
    
    # Referrer policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Set default character encoding
AddDefaultCharset UTF-8

# Disable directory browsing
Options -Indexes

# Protect sensitive files
<FilesMatch "^\.env">
    Order allow,deny
    Deny from all
</FilesMatch>

<FilesMatch "package\.json">
    Order allow,deny
    Deny from all
</FilesMatch>
